<!--新建/编辑考试类型-->
<template>
  <div>
    <el-dialog :title="dataForm.id?'编辑考试类型':'新建考试类型'" :visible.sync="dialogVisible" :close-on-click-modal="false" width="70%">
      <div class="my-form-container" style="height:422px">
          <el-row class="my-form-item">
            <el-col :span="24">
              <div class="my-form-item-label">考试类型名称</div>
              <div class="my-form-item-value">
                <el-input style="width: 372px;" v-model="dataForm.typeName"></el-input>
              </div>
            </el-col>
          </el-row>
          <el-row class="my-form-item">
            <el-col :span="24">
              <div class="my-form-item-label">负责单位</div>
              <div class="my-form-item-value">
                <el-select class="width140" v-model="dataForm.unitId">
                  <el-option v-for="item in xi" :key="item.id" :label="item.deptName" :value="item.id"></el-option>
                </el-select>
              </div>
            </el-col>
          </el-row>
          <el-row class="my-form-item">
            <el-col :span="24">
              <div class="my-form-item-label">总分</div>
              <div class="my-form-item-value">
                <el-input class="width88" v-model="dataForm.totalPoint"></el-input>
              </div>
            </el-col>
          </el-row>
          <el-row class="my-form-item">
            <el-col :span="24">
              <div class="my-form-item-label">分数线</div>
              <div class="my-form-item-value flex">
                  <div class="flex">
                      <span class="item-name">优秀线&nbsp;</span>
                      <el-input class="width88" v-model="dataForm.excellentLine"></el-input>
                  </div>
                  <div class="flex">
                      <span class="item-name">良好线&nbsp;</span>
                      <el-input class="width88" v-model="dataForm.goodLine"></el-input>
                  </div>
                  <div class="flex">
                      <span class="item-name">及格线&nbsp;</span>
                      <el-input class="width88" v-model="dataForm.passLine"></el-input>
                  </div>
              </div>
            </el-col>
          </el-row>
          <el-row class="my-form-item">
              <el-col :span="24">
                  <div class="my-form-item-label">主考</div>
                  <div class="my-form-item-value chose-student">
                      <el-input class="width140" v-model="dataForm.teacherName" disabled></el-input>
                      <div class="search-button color-green" @click="choseDialog">
                          <img src="../../../assets/assessment/icon-plan-record-detail.png" alt="" />
                          <span>选择</span>
                      </div>
                  </div>
              </el-col>
          </el-row>
          <el-row class="my-form-item" style="border:none;height:120px">
              <el-col :span="24">
                  <div class="my-form-item-label">备注</div>
                  <div class="my-form-item-value assessment-design">
                    <el-input type="textarea" v-model="dataForm.remarks" style="width: 372px;" :autosize="{ minRows: 3, maxRows: 4}"></el-input>
                  </div>
              </el-col>
          </el-row>
      </div>
      <div class="button-group" slot="footer">
        <div class="" @click="save">保存</div>
        <div class="" @click="dialogVisible=false">取消</div>
      </div>
    </el-dialog>
    <!-- 设置主考 -->
    <chosePeople ref="chosePeople" @chosePeople="peoples"></chosePeople>
  </div>
</template>

<script>
import {dataExtendList,addExamType,examTypeDetail} from "@/api/exam";
import chosePeople from "./setExaminer.vue"
export default {
  data() {
    return {
      dialogVisible:false,
      xi:[],//负责单位名称
      dataForm:{
        typeName:'',//类型名称
        unitId:'',//负责单位ID
        unitName:'',//负责单位名称
        excellentLine:'',//优秀线
        goodLine:'',//良好线
        passLine:'',//及格线
        remarks:'',//备注
        id:'',
        teacherName:'',
      },
    };
  },
  props:{ID:String },
  watch:{
    ID(val){
        if(val){
            this.dataForm.id = val;
            this.getDetail(val)
        }else{
            Object.assign(this.dataForm,this.$options.data().dataForm);
        }
    }
  },
  mounted(){
    this.commonApi.getXIOption().then(res=>{
      this.xi = res.data
    })
  },
  components:{chosePeople},
  methods: {
    async getDetail(ID){
      let res = await examTypeDetail({id:ID})
      this.dataForm = res.data
    },
    choseType(e){
      if(e.length!=0){
        this.checkList = [e[e.length-1]];
      }
    },
    choseDialog(){
      this.$refs.chosePeople.dialogVisible = true;
    },
    async save(){
      this.dataForm.unitName = this.xi.filter(item=>item.id == this.dataForm.unitId)[0].deptName
      let res = await addExamType(this.dataForm);
      if(res.code == 200){
        this.$message.success('保存成功')
        this.$emit('addCodeValue')
        this.dialogVisible = false;
      }
    },
    peoples(e){
      this.dataForm.teacherName = e.map(item=>item.xm).join(',')
      this.dataForm.teacherList = e.map(item=>{
        let val = {
          id :item.xpaasId,
          xm:item.xm
        }
        return val
      });
      console.log(e)
    }
  },
};
</script>
<style lang="less" scoped>
@import "../../../styles/commonCss.less";
/deep/.button-group{
  padding-bottom: 48px;
  margin-top: 0;
}
.width140{width: 140px;}
.width88{width: 88px;}
.my-form-container{width: 80%;}
.width90{width: 90px;}
/deep/ .my-form-item-label{
  justify-content: center;
  padding-left: 0!important;
}
.flex{
    display: flex;
    div{margin-right: 12px;}
}
.assessment-design {
    padding: 25px 38px !important;
    .el-textarea__inner {
        resize:none
    }
    .red-tip {
        margin: 0 7px;
        display: inline-block;
        vertical-align: 105px;
    }
}
.color-green{
    margin-left: 12px;
    background:#F1FFF8;
    border: 1px solid #02C86C;
    width: 78px;
    >span{color: #02C86C;}
    >img{width: 17px!important;height:17px!important}
}
</style>
